package com.soft.javase.day14;

import java.io.IOException;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/5/24
 */
public class BSDemo {
    public static void main(String[] args) {
        try (ServerSocket serverSocket = new ServerSocket(8888)) {
            System.out.println("服务器启动，监听 8888 端口...");

            while (true) {
                try (Socket socket = serverSocket.accept();
                     PrintStream ps = new PrintStream(socket.getOutputStream())) {

                    ps.println("HTTP/1.1 200 OK");
                    ps.println("Content-Type: text/html; charset=utf-8");
                    ps.println();
                    ps.println("欢迎 IP 上线！");

                } catch (IOException e) {
                    System.err.println("处理客户端请求时出错: ");
                }
            }
        } catch (IOException e) {
            System.err.println("服务器启动失败: ");
        }
    }
}
